16. LEFT and RIGHT JOIN

Select all of the below that are true.

SOLUTION:
  • A **LEFT JOIN** and **RIGHT JOIN** do the same thing if we change the tables that are in the **FROM** and **JOIN** statements.
  • A **LEFT JOIN** will **at least** return all the rows that are in an **INNER JOIN**.
  • **JOIN** and **INNER JOIN** are the same.
  • A **LEFT OUTER JOIN** is the same as **LEFT JOIN**.

Above are two small tables for you to test your knowledge of JOINs. You can click on the image to get a better view.

Country has 6 rows and 2 columns:

  • countryid and countryName

State has 6 rows and 3 columns:

  • stateid, countryid, and stateName

    Use the above tables to determine the solution to the following questions.

QUIZ QUESTION::

Match each statement to the item it describes.

ANSWER CHOICES:



Description

Item

State.stateid

State.stateName

Country.countryid

State.countryid

Country.countryName

SOLUTION:

Description

Item

State.stateid

Country.countryid

State.countryid

The above two tables are given again just for minimizing scrolling. If you were to perform the following query:

SELECT c.countryid, c.countryName, s.stateName
FROM Country c
JOIN State s
ON c.countryid = s.countryid;

QUIZ QUESTION::

Match the results of the query to the description.

ANSWER CHOICES:



Description

Result

12

5

7

1

8

4

2

0

3

6

SOLUTION:

Description

Result

2

0

3

6

The above two tables are given again just for minimizing scrolling. If you were to perform the following query:

SELECT c.countryid, c.countryName, s.stateName
FROM Country c
LEFT JOIN State s
ON c.countryid = s.countryid;

QUIZ QUESTION::

Match the results of the query to the description.

ANSWER CHOICES:



Description

Results

10

5

8

9

0

7

1

6

3

4

2

SOLUTION:

Description

Results

8

1

3

2